//***********************************************************************
//  Die.java  Java Foundations
//
//  Represents one die (singlar od dice) with faces showing value
//***********************************************************************

public class Die {
    private final int MAX = 6; // maximum face value

    private int faceValue; // current value showing on the die

    //------------------------------------------------------------
    //  Constructor: Sets the initial face value of this die.
    //------------------------------------------------------------
    public Die() {
        faceValue = 1;
    }

    //------------------------------------------------------------------
    //  Computer a new face value for this die and returns the result.
    //------------------------------------------------------------------
    public int roll() {
        faceValue = (int) (Math.random() * MAX) + 1;
        return faceValue;
    }
 
   //--------------------------------------------------------------------
   //  Face value mutator. The face value is not modidied if the 
   //  specified value not valid.
   //--------------------------------------------------------------------
   public void setFaceValue (int value)
   {
       if (value > 0 && value <= MAX)
           faceValue = value;
   }
   //--------------------------------------------------------------------
   // Face value accessor.
   //--------------------------------------------------------------------
   public int getFaceValue()
   {
     return faceValue;
   }
   //--------------------------------------------------------------------
   //  Rerurn a string representation of this die.
   //--------------------------------------------------------------------
   public String toString()
   {
     String result = Integer.toString(faceValue);
 
     return result;
   }
}

